package com.fengmi.controller;

import com.fengmi.dto.EntityDTO;
import com.fengmi.entity.MallGoods;
import com.fengmi.entity.ViewGoods;
import com.fengmi.service.MallGoodsService;
import com.fengmi.vo.GoodsSpuAndSkuVO;
import com.fengmi.vo.InfoResult;
import com.fengmi.vo.PageResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * Author: 施俊豪
 * Date: 2022/1/25 21:25
 * Note: 商品列表控制器
 */
@PreAuthorize("hasAnyRole('ROLE_PRODUCT')")
@CrossOrigin
@Api(tags="商品信息控制器")
@RequestMapping("/goods")
@RestController
public class MallGoodsController {
    @Autowired
    private MallGoodsService mallGoodsService;

    @ApiOperation("分页+条件查询商品信息")
    @RequestMapping("/findGoods")
    public PageResult<ViewGoods> findGoodsByPage(@ApiParam("查询条件实体类") @RequestBody EntityDTO<MallGoods> entity){
        return mallGoodsService.findGoodsByPage(entity);
    }

    @ApiOperation("商品添加")
    @RequestMapping("/addGoods")

    public InfoResult addGoods(@ApiParam("插入数据") @RequestBody GoodsSpuAndSkuVO spuAndSkuVO){
        return mallGoodsService.addGoodsAndSku(spuAndSkuVO);
    }

    @ApiOperation("商品删除")
    @DeleteMapping("/delGoods")
    public InfoResult deleteGoods(@ApiParam("删除的商品品牌集合")@RequestBody Integer[] ids){
        return mallGoodsService.delGoodsAndSku(ids);
    }
}
